package com.lee.study.shouji.engine;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.xmlpull.v1.XmlPullParserException;

import com.lee.study.shouji.R;
import com.lee.study.shouji.domain.UpdateInfo;

import android.content.Context;

/**
 * @description 负责APP的更新操作
 *
 * @author AlexLee
 *
 * @Create 2013-5-27 上午9:31:45
 */
public class UpdateInfoService {

	public Context context;
	
	public UpdateInfoService(Context context) {
		this.context = context;
	}
	
	/**
	 * 从服务器得到更新信息
	 * @param urlid 服务器路径String 对应的id
	 * @return
	 * @throws IOException 
	 * @throws XmlPullParserException 
	 */
	public UpdateInfo getUpdateInfo(int urlid) throws IOException, XmlPullParserException{
		
		String updateUrl = context.getResources().getString(R.string.updateurl);
		
		URL url = new URL(updateUrl);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setConnectTimeout(5000);
		connection.setRequestMethod("GET");
		
		InputStream is = connection.getInputStream();
		UpdateInfo updateInfo = UpdateInfoParser.getUpdateInfo(is);
		
		return updateInfo;
	}
	
}
